{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {}
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import time\n",
    "import os\n",
    "import requests\n",
    "\n",
    "import fml_manager\n",
    "from fml_manager import *\n",
    "\n",
    "manager = fml_manager.FMLManager()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## For more details about the FMLManager, please refer to this [document](https://kubefate.readthedocs.io/README.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'data': {'detail': {'guest': {'10000': {'retcode': 0, 'retmsg': 'success'}}, 'host': {'9999': {'retcode': 0, 'retmsg': 'success'}}}, 'guest': {'10000': 0}, 'host': {'9999': 0}}, 'jobId': '2021091703434276413179', 'retcode': 0, 'retmsg': 'success'}\n"
     ]
    }
   ],
   "source": [
    "manager = fml_manager.FMLManager()\n",
    "initiator_party_id=10000\n",
    "federated_roles= {\n",
    "        \"guest\": [\"10000\"],\n",
    "        \"host\": [\"9999\"],\n",
    "        \"arbiter\": [\"9999\"]}\n",
    "work_mode=1\n",
    "model_id='arbiter-9999#guest-10000#host-9999#model'\n",
    "model_version='2021091507054902485058'\n",
    "response = manager.load_model(initiator_party_id, federated_roles, work_mode, model_id, model_version)\n",
    "output = json.loads(response.content)\n",
    "print(output)\n",
    "#guest_job_id = output['jobId']\n",
    "#guest_query_condition = QueryCondition(job_id=guest_job_id)\n",
    "#manager.query_job_status(guest_query_condition, max_tries=20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Click [here](/fateboard-10000/) to view jobs in FATE Board"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'retcode': 0, 'retmsg': 'service id is test'}\n"
     ]
    }
   ],
   "source": [
    "service_id='test'\n",
    "initiator_party_id='10000' #not int\n",
    "response = manager.bind_model(service_id,initiator_party_id, federated_roles, work_mode, model_id, model_version)\n",
    "output = json.loads(response.content)\n",
    "print(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
